package sldm;

import java.lang.reflect.Field;

public class sl8 {
    public static void main(String[] args) {
        try {
            Class clz = Class.forName("entry.Person");
            Object person = clz.newInstance();

            //获取private String name 属性
            Field name = clz.getDeclaredField("name");
            name.setAccessible(true);
            //先取值看一下
            System.out.println("赋值前的name: "+ name.get(person));
            //为name赋值
            name.set(person,"New Person");
            //展示赋值效果
            System.out.println("赋值后的name:" + name.get(person));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
